"""
u5_FreeVRAM - ComfyUI Custom Node for Memory Management
MIT License - Copyright (c) 2024

This node provides memory management functionality for ComfyUI workflows.
It allows unloading models, clearing caches, and freeing memory without
disrupting the workflow execution.
"""

# ========================================
# Existing Node - Protected
# ========================================
from .model_unloader import VRAMFreeNode

# ========================================
# New Addition: Sequential Loaders
# ========================================
SEQUENTIAL_LOADERS_AVAILABLE = False

try:
    from .sequential_loaders import (
        SequentialCheckpointLoader,
        SequentialLoRALoader,
        SequentialCLIPLoaderSimple,
        SequentialVAELoaderSimple,
    )
    SEQUENTIAL_LOADERS_AVAILABLE = True
    print("[FreeVRAM] Sequential Loaders loaded successfully (ComfyUI standard only)")
except ImportError as e:
    print(f"[FreeVRAM] Sequential Loaders not available: {e}")
    print("[FreeVRAM] Core FreeVRAM node will work normally")

# ========================================
# Node Registration
# ========================================
NODE_CLASS_MAPPINGS = {
    # Existing node (always available)
    "VRAMFree": VRAMFreeNode,
}

NODE_DISPLAY_NAME_MAPPINGS = {
    "VRAMFree": "FREE VRAM (u5)",
}

# Sequential Loaders (only if available)
if SEQUENTIAL_LOADERS_AVAILABLE:
    NODE_CLASS_MAPPINGS.update({
        "SequentialCheckpointLoader": SequentialCheckpointLoader,
        "SequentialLoRALoader": SequentialLoRALoader,
        "SequentialCLIPLoaderSimple": SequentialCLIPLoaderSimple,
        "SequentialVAELoaderSimple": SequentialVAELoaderSimple,
    })

    NODE_DISPLAY_NAME_MAPPINGS.update({
        "SequentialCheckpointLoader": "Sequential Checkpoint Loader",
        "SequentialLoRALoader": "Sequential LoRA Loader",
        "SequentialCLIPLoaderSimple": "Sequential CLIP Loader",
        "SequentialVAELoaderSimple": "Sequential VAE Loader",
    })

# Version information
__version__ = "1.1.0"  # Sequential Loaders added
__license__ = "MIT"
__author__ = "u5_FreeVRAM Development Team"

# Web UI
WEB_DIRECTORY = "./js"